﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Cole.Entities;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace Cole.Repository
{
    public class DocenteRepository :MasterRepository, IDocenteRepository
    {
        public List<Docente> GetAllFromDocentes()
        {
            var query = _database.ExecuteSprocAccessor<Docente>("GetAllFromDocentes");
            return query.ToList();
        }

        public List<Docente> GetFromDocentesByCriterio(string criterio)
        {
            var param = new object[] {criterio,0};
            var query = _database.ExecuteSprocAccessor<Docente>("GetFromDocentesByCriterio", param);

            return query.ToList(); 
        }

        public Docente GetFromDocenteById(int id)
        {
            var query = _database.ExecuteSprocAccessor<Docente>("GetFromDocentesById", id);

            return query.SingleOrDefault();
        }

        public void AddDocente(Docente docente)
        {
            var command = _database.GetStoredProcCommand("RegistrarDocente");
            _database.AddInParameter(command, "Id", DbType.Int32, docente.Id);
            _database.AddInParameter(command, "Nombres", DbType.String, docente.Nombres);
            _database.AddInParameter(command, "Apellidos", DbType.String, docente.Apellidos);
            _database.AddInParameter(command, "Especialidad", DbType.String, docente.Especialidad);
            _database.AddInParameter(command, "Email", DbType.String, docente.Email);
            _database.AddInParameter(command, "Telefono", DbType.String, docente.Telefono);            

            _database.ExecuteNonQuery(command);

        }

        public void UpdateDocente(Docente docente)
        {
            throw new NotImplementedException();
        }

        public void RemoveDocente(int id)
        {
            
            var command = _database.GetStoredProcCommand("DeleteDocente");

            _database.AddInParameter(command, "Id", DbType.Int32, id);

            _database.ExecuteNonQuery(command);
        }
    }
}
